//
//  BQShopCell.m
//  BeeQuick
//
//  Created by student on 2017/7/13.
//  Copyright © 2017年 BecomeRich. All rights reserved.
//

#import "BQShopCell.h"
#import "BQShopModelArrayManager.h"

@interface BQShopCell ()

@property (weak, nonatomic) IBOutlet UILabel *chosenLable;
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLable;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UIButton *relessButton;
@property (weak, nonatomic) IBOutlet UILabel *numLable;
@property (weak, nonatomic) IBOutlet UIButton *addButton;


@end

@implementation BQShopCell


- (IBAction)relessButtonAction:(UIButton *)sender {
   
    NSMutableArray *arr = [BQShopModelArrayManager manager].modelArray;
    BQProductModel *model = [[BQProductModel alloc]init];
    model = arr[sender.tag];
        if (model.count == 1) {
        [[BQShopModelArrayManager manager] shopModelArrayManagerReduceWithModel:model];
        
    }
    model.count -=  1;
    self.numLable.text = [NSString stringWithFormat:@"%zd",model.count];
    [[BQShopModelArrayManager manager] shopClick];
    [[BQShopModelArrayManager manager] tabBarShowCount];

}
- (IBAction)addButtonAction:(UIButton *)sender {
    
    NSMutableArray *arr = [BQShopModelArrayManager manager].modelArray;
    BQProductModel *model = [[BQProductModel alloc]init];
    model = arr[sender.tag];
    if (model.count >= model.number) {
        NSString * str = [model.name stringByAppendingString:@"库存不足了,请等待货源充足再购买~"];
        [SVProgressHUD showImage:[UIImage imageNamed:@"v2_orderSuccess"] status:str];
        [SVProgressHUD dismissWithDelay:1.0];
        return;
    }
     model.count += 1;
    self.numLable.text = [NSString stringWithFormat:@"%zd",model.count];
    [[BQShopModelArrayManager manager] shopClick];
    [[BQShopModelArrayManager manager] tabBarShowCount];

}

- (void)awakeFromNib {
    [super awakeFromNib];
 
}

- (void)setModel:(BQProductModel *)model{
    self.chosenLable.text = @"[精选]";
    self.goodsNameLable.text = model.name;
    self.priceLabel.text = [NSString stringWithFormat:@"%.2f",model.price];
    self.numLable.text = [NSString stringWithFormat:@"%zd",model.count];
    self.addButton.tag = model.tag;
    self.relessButton.tag = model.tag;
}
@end
